/* Turska Framework/UI library (Turs2)
 * Copyright 2003-2008 Jetro Lauha
 * All rights reserved.
 * Web: http://iki.fi/jetro/turska/
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of EITHER:
 *   (1) The GNU Lesser General Public License as published by the Free
 *       Software Foundation; either version 2.1 of the License, or (at
 *       your option) any later version. The text of the GNU Lesser
 *       General Public License is included with this library in the
 *       file LICENSE-LGPL.txt.
 *   (2) The BSD-style license that is included with this library in
 *       the file LICENSE-BSD.txt.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files
 * LICENSE-LGPL.txt and LICENSE-BSD.txt for more details.
 *
 * $Id: errormsg.c 34 2008-04-19 00:16:09Z jlauha $
 * $Revision: 34 $
 */

#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif

#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>

#include "errormsg.h"


static void sShowError(char *title, char *msg, va_list ap)
{
#ifdef WIN32
#define BUFLEN 2048
    char s[BUFLEN] = { 0 };
#if _MSC_VER >= 1300
    _vsnprintf_s(s, BUFLEN, _TRUNCATE, msg, ap);
#else
    _vsnprintf(s, BUFLEN - 1, msg, ap);
#endif
    MessageBoxA(0, s, title, MB_OK | MB_APPLMODAL | MB_ICONEXCLAMATION);
#undef BUFLEN
#else
    fflush(stderr);
    fflush(stdout);
    fprintf(stderr, "\n%s: ", title);
    vfprintf(stderr, msg, ap);
    fprintf(stderr, "\n");
    fflush(stderr);
#endif
}


void gErrorMessage(char *title, char *msg, ...)
{
    va_list ap;
    va_start(ap, msg);
    sShowError(title, msg, ap);
}
